package com.juicygames.framework.gamepart;

import com.juicygames.framework.GameAction;

public abstract class GameHandler<ActionTypeParam extends GameAction> extends GamePart {
	
	protected GamePart self;

	private Class<ActionTypeParam> actionClassHandled;
	
	public GameHandler(GamePart self) {
		super(self);
		this.self = self;
	}

	public void handle(ActionTypeParam action) {
	}
	
	public boolean handlesClass(GameAction action) {
		Class<? extends GameAction> actionClass = action.getClass();
		return actionClass.equals(actionClassHandled);
	}
	
	public void groundHandler() {
		if (parent != null) {
			parent.groundHandler(this);
		}
	} 
	
	public GamePart getParent() {
		return self;
	}
	
	public Class<ActionTypeParam> getActionClassHandled() {
		return actionClassHandled;
	}

	public void setActionClassHandled(Class<ActionTypeParam> handlerTriggerClass) {
		this.actionClassHandled = handlerTriggerClass;
	}
	
	public GamePart getSelf() {
		return self;
	}

}
